﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>辅材库存统计查询</title>
  <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
  <link rel="stylesheet" href="/InSiteWebApplication/Content/webuploader/webuploader.css" />
  <style>
    .easyui-linkbutton {
      margin-left: 20px;
    }

    table tr td {
      padding: 0px 5px
    }

    .Btitle {
      background-color: #ddd;
      padding: 10px;
      margin: 5px 10px;
    }

    .webuploader-pick {
      padding: 0px 0px;
      border-radius: 0px
    }
  </style>
</head>

<body>
  <div class="panelSection">
    <div class="easyui-panel " title="查询区域" style="padding:3px;width:100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <form id="searchForm" method="post">
        <table>
          <tr class="divLabel">
            <td>材料编码:</td>
            <td>材料描述:</td>
          </tr>
          <tr>
            <td><input name="Name" class="easyui-textbox" style="width: 120px; height: 22px" /></td>
            <td><input name="Description" class="easyui-textbox" style="width: 120px; height: 22px" /></td>
            <td> <span style="margin-right: 5px;"><input type="radio" name="Status" value="0" checked="true"
                  id="Status" /><label for="Status">只显示异常</label></span>
              <input type="radio" name="Status" value="1" id="Status1" /><label for="Status1">显示全部</label>
            </td>
            <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a></td>
            <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a></td>
          </tr>
        </table>
      </form>
    </div>
  </div>

  <div class="panelSection">
    <div class="easyui-panel " title="材料库存统计" style="padding:3px;width:100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <table id="NotProductMaterialStoreCensus" style="height:440px;width:100%" data-options="rownumbers:true"></table>
      <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]
                ">
      </div>
      <div style="margin-top:7px;">
        <span class="divLabel">安全库存量:</span><input class="easyui-numberbox" style="width: 120px; height: 22px"
          id="safeQty" />
        <span class="divLabel">最小库存量:</span><input class="easyui-numberbox" style="width: 120px; height: 22px"
          id="minQty" />
      </div>
    </div>
  </div>

  <div class="panelSection">
    <div class="easyui-panel " title="按钮区域" style="padding:3px;width:100%">
      <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.setNotProductMaterialStoreQty()">设定库存</a>
      <a href="javascript:void(0)" class="easyui-linkbutton" style="height:auto"
        id="importNotProductMaterialStoreQty">材料库存台账导入</a>
      <span style="color:red;font-weight:bold;margin-left: 10px;">内部系统，严禁上传涉密信息</span>
      <input id="txtExcelFileId" type="hidden" />
    </div>
  </div>

  <!--信息提示区域-->
  <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
</body>

</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/webuploader/webuploader.js"></script>
<script>
  //创建人：longb
  //日期：2022-07-22
  //描述：材料库存统计查询
  var page = {
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    index: null,
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSReciveMaterialConfirmHandler.ashx",
    //初始化页面
    init: function () {
      page.bind();
      customizedEasyuiPagination('pp'); //定制化分页
      page.InitUploader();
    },
    //页面事件绑定
    bind: function () {
      $('#NotProductMaterialStoreCensus').datagrid({
        checkOnSelect: true,
        selectOnCheck: false,
        singleSelect: true,
        rownumbers: true,
        onLoadSuccess: function (data) {
          $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
            total: page.pagetotal,
            pageSize: page.pageSize,
            pageNumber: page.pageNumber
          });
          customizedEasyuiPagination('pp'); //定制化分页
        },
        columns: [[
          // { field: 'ck', title: '选择', checkbox: true },
          { field: 'MATNR', title: '材料编码', width: 140 },
          { field: 'MAKTX', title: '材料描述', width: 140 },
          { field: 'SPECIFICATION', title: '型号规格', width: 90 },
          { field: 'MTART', title: '材料类型', width: 100 },
          { field: 'SAFESTOCKQTY', title: '安全库存量', width: 80 },
          { field: 'MINSTOCKQTY', title: '最小库存量', width: 90, align: 'center' },
          { field: 'LABST', title: '当前库存量', width: 100 },
          { field: 'EINME', title: '当前送检数量', width: 130 },
          { field: 'UMLMC', title: '采购在途数量', width: 130 },
          {
            field: 'STATUS', title: '库存状态', width: 130, styler: function (value, row, index) {
              if (value == "建议采购") { return 'color:orange;'; }
              else if (value == "急需采购") { return 'color:red;'; }
              else { return 'color:green;'; }
            }
          }
        ]],
        onSelect: function (index, row) {
          $('#minQty').numberbox('setValue', row.MINSTOCKQTY);
          $('#safeQty').numberbox('setValue', row.SAFESTOCKQTY);
        }
      });
      //分页事件
      $('#pp').pagination({
        onSelectPage: function (pageNumber, pageSize) {
          customizedEasyuiPagination('pp'); //定制化分页
          page.pageSize = pageSize; page.pageNumber = pageNumber;
          page.GetNotProductMaterialStoreCensus();
        }
      });
      //绑定分页go按钮
      $('#pageGo').on("click", function () {
        var pageNumber = $(this).parents('tr').find('.pagination-num').val();
        page.pageNumber = pageNumber;
        page.GetNotProductMaterialStoreCensus();
      });
      //清除按钮
      $('#btnReset').on("click", function () {
        page.reset(true, true);
        page.pageNumber = 1; page.pagetotal = 0
        $('#pp').pagination('refresh', {
          total: page.pagetotal,
          pageSize: page.pageSize,
          pageNumber: page.pageNumber
        });
      });
    },
    //查询
    searchData: function () {
      clearMessage();
      page.pageNumber = 1;
      page.GetNotProductMaterialStoreCensus();
    },
    //查询重置
    searchReset: function () {
      $('#searchForm').form('clear');
      $('#Status').prop("checked", true);
      clearMessage();
    },
    //查询任务单信息
    GetNotProductMaterialStoreCensus: function () {
      var frdata = $('#searchForm').serializeArray();
      var data = {};
      $.each(frdata, function () {
        data[this.name] = this.value
      });
      var param = {
        action: "GetNotProductMaterialStoreCensus",
        pageSize: page.pageSize,
        pageNumber: page.pageNumber,
        data: JSON.stringify([data])
      };
      page.post(param, function (res) {
        page.pagetotal = res.RowCount;
        $('#NotProductMaterialStoreCensus').datagrid('loadData', res.DBTable);
      });
    },
    //设定库存
    setNotProductMaterialStoreQty: function () {
      var row = $('#NotProductMaterialStoreCensus').datagrid('getSelected');
      if (row == null) { displayMessage('请选择一条库存信息再进行操作', false); return; }
      var param = {
        action: 'SaveNotProductMaterialStoreQty',
        data: JSON.stringify({ matNR: row.MATNR, makTX: row.MAKTX, minQty: $('#minQty').numberbox('getValue'), safeQty: $('#safeQty').numberbox('getValue') })
      }
      page.post(param, function (res) {
        if (res.Result) {
          page.GetNotProductMaterialStoreCensus();
        }
        displayMessage(res.Message, res.Result);
      });
    },
    //库存台账导入
    //导入组件初始化
    InitUploader: function () {
      var uploader = WebUploader.create({
        // swf文件路径
        swf: page.rootPath + "/Content/webuploader/Uploader.swf",
        // 文件接收服务端。
        server: page.ajaxUrl,
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: '#importNotProductMaterialStoreQty',
        // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
        resize: false,
        formData: {
          action: "importNotProductMaterialStoreQty",
        },
        accept: {
          title: 'Excel',
          extensions: 'xlsx,xls',
          mimeTypes: 'excel/*'
        },
      });
      // 当有文件被添加进队列的时候，每次只传一个文件
      uploader.on('fileQueued', function (file) {
        if ($('#txtExcelFileId').val() != "") {
          var f = uploader.getFile($('#txtExcelFileId').val()); //找到上一次队列中的文件
          uploader.removeFile(f, true); //删除掉上一次队列中的文件
        }
        $('#txtExcelFileId').val(file.id);
        displayMessage("", true);
        uploader.upload();
        $.messager.progress({ text: '', msg: '处理中...' });
      });
      //上传成功
      uploader.on('uploadSuccess', function (file, response) {
        var result = response;
        displayMessage(result.Message, result.Result);
        $.messager.progress('close');
        var f = uploader.getFile(file.id); //找到上传的文件
        uploader.removeFile(f, true); //将其从队列中的删掉
        $('#txtExcelFileId').val("");
        page.GetNotProductMaterialStoreCensus();
      });
      //上传失败
      uploader.on('uploadError', function (file) {
        displayMessage("上传失败", false);
        var f = uploader.getFile(file.id); //找到上传的文件
        uploader.removeFile(f, true); //将其从队列中的删掉
        $.messager.progress('close');
        $('#txtExcelFileId').val("");

      });
    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
      clearMessage();
    },
    //post数据
    post: function (param, callback) {
      $.ajax({
        type: "Post",
        url: page.ajaxUrl,
        data: param,
        cashe: false,
        async: true,
        dataType: "json",
        beforeSend: function () {
          $.messager.progress({ text: '', msg: '处理中...' });
        },
        success: function (data) {
          $.messager.progress('close');
          callback(data);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $.messager.progress('close');
          displayMessage(XMLHttpRequest.responseText, false);
        }
      });
    }
  }
  $(function () {
    page.init();
  });
</script>